package com.hy.controller;

import com.hy.bean.ReceiveApplyDetail;
import com.hy.bean.ResponseResult;
import com.hy.service.ReceiveApplyDetailService;
import com.hy.service.impl.ReceiveApplyDetailServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("receiveDetail")
public class ReceiveApplyDetailController {
    ReceiveApplyDetailService receiveApplyDetailService = new ReceiveApplyDetailServiceImpl();
    @PostMapping("add")
    public ResponseResult add(@RequestBody ReceiveApplyDetail receiveApplyDetail) throws Exception {
        Boolean flag = receiveApplyDetailService.insert(receiveApplyDetail);
        if (flag)
            return new ResponseResult(200,"插入成功",10001,flag);
        else
            return new ResponseResult(250,"插入失败",10000,flag);
    }

    @GetMapping("queryDetail/{id}")
    public ResponseResult queryDetail(@PathVariable Integer id) throws Exception {
        return new ResponseResult(200,"查询完成",1000,receiveApplyDetailService.select(id));
    }

    @PutMapping("modify")
    public ResponseResult modify(@RequestBody ReceiveApplyDetail receiveApplyDetail) throws Exception {
        return new ResponseResult(200,"修改完成",1000,receiveApplyDetailService.update(receiveApplyDetail));
    }

    @DeleteMapping("removeDetail/{lymxid}")
    public ResponseResult removeDetail(@PathVariable String lymxid) throws Exception {
        return new ResponseResult(200,"修改完成",1000,receiveApplyDetailService.delete(lymxid));
    }

    @GetMapping("query/{status}")
    public ResponseResult query(@PathVariable String status) throws Exception {
        if (StringUtils.isBlank(status) || status.equals("null"))
            status = null;

        return new ResponseResult(200,"查询完成",1000,receiveApplyDetailService.select(status));
    }
}
